import React, { Component } from 'react';
import CommentItem from './CommentItem'

class CommentList extends Component{
  constructor(){
    super()
    
  }

  static defaultProps = {
    comments: []
  }

  render(){
    return (
      <div className="comment-list">
        {this.props.comments.map((comment, i) => {
          return (
            <CommentItem comment={comment} key={i} index={i} onDelete={this.onDeleteComment.bind(this)}></CommentItem>
          )
        })}
      </div>
    )
  }

  onDeleteComment(index){
    if(this.props.onDelete){
      this.props.onDelete({index:index})
    }
  }
}

export default CommentList